//
//  DHPostTaskController.m
//  精品酒店
//
//  Created by DIANGHONG on 2018/5/17.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "DHPostTaskController.h"
#import "DHOrderButton.h"
#import "DHMyPostTaskCell.h"
#import <AlipaySDK/AlipaySDK.h>
#import "APOrderInfo.h"
#import <WXApi.h>
#import <WXApiObject.h>
#import "APRSASigner.h"
NSString *mypostTaskCellID = @"mypostTaskCellID";
@interface DHPostTaskController ()<UITableViewDataSource,DHIsFinishedCellDelegate, JPPayViewDelegate, UITableViewDelegate,CLLocationManagerDelegate>
@property(nonatomic ,strong)UIView *filterView;
@property(nonatomic ,strong)DHOrderButton *currentBtn; //记录当前选中按钮
@property(nonatomic ,strong)NSString *status;
@property(nonatomic ,assign)int curpage;
@property(nonatomic ,strong)DHCleanOrderDataModel *model;
@property(nonatomic ,strong)UITableView *tableView;

@property(nonatomic, strong)JPPayView *payView;

@property(nonatomic, strong)CYPasswordView *pwdView;


@property (nonatomic,strong ) CLLocationManager *locationManager;//定位服务
@property (nonatomic,copy) NSString *currentCity;   //城市
@property (nonatomic,copy) NSString *strLatitude;   //经度
@property (nonatomic,copy) NSString *strLongitude;  //维度

@end

@implementation DHPostTaskController
- (void)setModel:(DHCleanOrderDataModel *)model
{
    _model = model;
    
    [self.tableView reloadData];
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self setupNavBar];
}
- (UIView *)filterView
{
    if (!_filterView) {
        _filterView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.navigationController.navigationBar.frame), kScreenWidth, 44)];
        _filterView.backgroundColor = UIColor.redColor;
        [self setupFilterView];
    }
    return _filterView;
}
- (void)setupFilterView
{
    DHOrderButton *allButton = [DHOrderButton orderButtonWithFrame:CGRectMake(0, 0, kScreenWidth / 4, _filterView.bounds.size.height) title:@"全部"];
    DHOrderButton *unOrderButton = [DHOrderButton orderButtonWithFrame:CGRectMake(CGRectGetMaxX(allButton.frame), 0, allButton.bounds.size.width, allButton.bounds.size.height) title:@"未接单"];
      DHOrderButton *doingButton = [DHOrderButton orderButtonWithFrame:CGRectMake(CGRectGetMaxX(unOrderButton.frame), 0, allButton.bounds.size.width, allButton.bounds.size.height) title:@"进行中"];
    DHOrderButton *finishedButton = [DHOrderButton orderButtonWithFrame:CGRectMake(CGRectGetMaxX(doingButton.frame), 0, allButton.bounds.size.width, allButton.bounds.size.height) title:@"已完成"];
    
    [allButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [unOrderButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [doingButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [finishedButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    allButton.tag = -1;
    unOrderButton.tag = 0;
    doingButton.tag = 1;
    finishedButton.tag = 2;

    // 默认点击全部
    [self buttonClick:allButton];

    [_filterView addSubview:allButton];
    [_filterView addSubview:unOrderButton];
    [_filterView addSubview:doingButton];
    [_filterView addSubview:finishedButton];

}

- (void)locatemap{
    
    if ([CLLocationManager locationServicesEnabled]) {
        _locationManager = [[CLLocationManager alloc]init];
        _locationManager.delegate = self;
        [_locationManager requestAlwaysAuthorization];
        _currentCity = [[NSString alloc]init];
        [_locationManager requestWhenInUseAuthorization];
        _locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        _locationManager.distanceFilter = 5.0;
        [_locationManager startUpdatingLocation];
    }
}


#pragma mark - 定位失败
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请在设置中打开定位" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *ok = [UIAlertAction actionWithTitle:@"打开定位" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSURL *settingURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
        [[UIApplication sharedApplication]openURL:settingURL];
    }];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alert addAction:cancel];
    [alert addAction:ok];
    [self presentViewController:alert animated:YES completion:nil];
}
#pragma mark - 定位成功
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
{
    
    [_locationManager stopUpdatingLocation];
    CLLocation *currentLocation = [locations lastObject];
    CLGeocoder *geoCoder = [[CLGeocoder alloc]init];
    //当前的经纬度
    NSLog(@"当前的经纬度 %f,%f",currentLocation.coordinate.latitude,currentLocation.coordinate.longitude);
    
    self.strLongitude = [NSString stringWithFormat:@"%f",currentLocation.coordinate.longitude];
    self.strLatitude =  [NSString stringWithFormat:@"%f",currentLocation.coordinate.latitude];;
    //这里的代码是为了判断didUpdateLocations调用了几次 有可能会出现多次调用 为了避免不必要的麻烦 在这里加个if判断 如果大于1.0就return
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        //地理反编码 可以根据坐标(经纬度)确定位置信息(街道 门牌等)
        [geoCoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
            if (placemarks.count >0) {
                CLPlacemark *placeMark = placemarks[0];
                self->_currentCity = placeMark.locality;
                if (!self->_currentCity) {
                    self->_currentCity = @"无法定位当前城市";
                }
                //看需求定义一个全局变量来接收赋值
                //            NSLog(@"当前国家 - %@",placeMark.country);//当前国家
                NSLog(@"当前城市 - %@",self->_currentCity);//当前城市
                //self.leftNavButton.titleLabel.text = self->_currentCity;
                //[self.addrBtn setTitle:self->_currentCity forState:UIControlStateNormal];
                //            NSLog(@"当前位置 - %@",placeMark.subLocality);//当前位置
                //            NSLog(@"当前街道 - %@",placeMark.thoroughfare);//当前街道
                //            NSLog(@"具体地址 - %@",placeMark.name);//具体地址
                NSString *message = [NSString stringWithFormat:@"%@,%@,%@,%@,%@",placeMark.country,self->_currentCity,placeMark.subLocality,placeMark.thoroughfare,placeMark.name];
                
                UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:message delegate:self cancelButtonTitle:nil otherButtonTitles:@"好", nil];
                //            [alert show];
            }else if (error == nil && placemarks.count){
                
                NSLog(@"NO location and error return");
            }else if (error){
                
                NSLog(@"loction error:%@",error);
            }
        }];
    });
   // [self loadHomeTaskListWithPullUP:NO];
}
#pragma mark: - 全部、未接单、进行中、已完成按钮监听
- (void)buttonClick:(DHOrderButton *)sender
{
    self.currentBtn.selected = false;
    sender.selected = true;
    self.currentBtn = sender;
    
    switch (sender.tag)
    {
        case -1:
            self.status = @"-1";
            break;
        case 0:
            self.status = @"0";
            break;
        case 1:
            self.status = @"1";
            break;
        case 2:
            self.status = @"2";
            break;
    }
    self.model = nil;
    self.curpage = 1;
    [self.tableView.mj_header beginRefreshing];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupTableView];
    [self.view addSubview:self.filterView];
    [self locatemap];
    
    // 监听一个通知
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getOrderPayResult:) name:@"ORDER_PAY_NOTIFICATION" object:nil];
    
    [self.tableView.mj_header beginRefreshing];
    self.pwdView = [[CYPasswordView alloc] init];
    self.pwdView.title = @"输入支付密码";
    
    self.payView = [[JPPayView alloc] initWithFrame:CGRectMake(0,CGRectGetMaxY([UIApplication.sharedApplication keyWindow].frame), kScreenWidth, kScreenHeight)];
    self.payView.delegate = self;
    // self.payView.backgroundColor = [UIColor redColor];
    [[UIApplication.sharedApplication keyWindow] addSubview:self.payView];
    
    [self loadPayList];
    
    
    self.curpage = 1;
}
#pragma mark - 微信收到支付成功的消息后作相应的处理
- (void)getOrderPayResult:(NSNotification *)notification

{
    
    if ([notification.object isEqualToString:@"success"]) {
        
        NSLog(@"支付成功");
        
        [SVProgressHUD showSuccessWithStatus:@"支付成功"];
        
    } else {
        
        NSLog(@"支付失败");
        
        [SVProgressHUD showErrorWithStatus:@"支付失败"];
        
    }
    
    
    
}
#pragma mark: - JPPayViewDelegate
- (void)payView:(JPPayView *)view balancePay:(NSMutableDictionary *)dict
{
    
    [UIView animateWithDuration:0.25 animations:^{
        self.payView.transform = CGAffineTransformIdentity;
    }];
    
    [self.pwdView showInView:self.view];
    __weak typeof(self) WeakSelf = self;
    self.pwdView.finish = ^(NSString *password)
    {
        [WeakSelf.pwdView hideKeyboard];
       // [WeakSelf.pwdView startLoading];
        dict[@"paypwd"] = password;
        
        [DHNetworkManager.shareManager requestWithMethod:MethodPost
                                               UrlString:kPayBalanceUrl params:dict.copy
                                              completion:^(id json, BOOL isSuccess)
         {
             [WeakSelf.pwdView stopLoading];
             if (!isSuccess) {
                 [SVProgressHUD showErrorWithStatus:@"请检查网络"];
                // [WeakSelf.pwdView requestComplete:YES];
                 [WeakSelf.pwdView hide];return ;
             }
             id tem = json[@"datas"];
             if (tem[@"error"]) {
                 [SVProgressHUD showErrorWithStatus:tem[@"error"]];
                 [WeakSelf.pwdView requestComplete:NO];
                 //[WeakSelf.pwdView hide];
                 
                 return ;
                 
             }
             [SVProgressHUD showSuccessWithStatus:tem[@"succ"]];
             //[WeakSelf.pwdView hide];
             
             
             [WeakSelf.pwdView requestComplete:NO];
             
         }];
    };
}

- (void)payView:(JPPayView *)view aliPay:(NSMutableDictionary *)dict
{
    [UIView animateWithDuration:0.25 animations:^{
        self.payView.transform = CGAffineTransformIdentity;
    }];
    // 重要说明
    // 这里只是为了方便直接向商户展示支付宝的整个支付流程；所以Demo中加签过程直接放在客户端完成；
    // 真实App里，privateKey等数据严禁放在客户端，加签过程务必要放在服务端完成；
    // 防止商户私密数据泄露，造成不必要的资金损失，及面临各种安全风险；
    /*============================================================================*/
    /*=======================需要填写商户app申请的===================================*/
    /*============================================================================*/
    NSString *appID = @"";
    
    // 如下私钥，rsa2PrivateKey 或者 rsaPrivateKey 只需要填入一个
    // 如果商户两个都设置了，优先使用 rsa2PrivateKey
    // rsa2PrivateKey 可以保证商户交易在更加安全的环境下进行，建议使用 rsa2PrivateKey
    // 获取 rsa2PrivateKey，建议使用支付宝提供的公私钥生成工具生成，
    // 工具地址：https://doc.open.alipay.com/docs/doc.htm?treeId=291&articleId=106097&docType=1
    NSString *rsa2PrivateKey = @"";
    NSString *rsaPrivateKey = @"";
    /*============================================================================*/
    /*============================================================================*/
    /*============================================================================*/
    
    //partner和seller获取失败,提示
    if ([appID length] == 0 ||
        ([rsa2PrivateKey length] == 0 && [rsaPrivateKey length] == 0))
    {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"
                                                                       message:@"缺少appId或者私钥,请检查参数设置"
                                                                preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"知道了"
                                                         style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction *action){
                                                           
                                                       }];
        [alert addAction:action];
        [self presentViewController:alert animated:YES completion:^{ }];
        return;
    }
    
    /*
     *生成订单信息及签名
     */
    //将商品信息赋予AlixPayOrder的成员变量
    APOrderInfo* order = [APOrderInfo new];
    
    // NOTE: app_id设置
    order.app_id = appID;
    
    // NOTE: 支付接口名称
    order.method = @"alipay.trade.app.pay";
    
    // NOTE: 参数编码格式
    order.charset = @"utf-8";
    
    // NOTE: 当前时间点
    NSDateFormatter* formatter = [NSDateFormatter new];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    order.timestamp = [formatter stringFromDate:[NSDate date]];
    
    // NOTE: 支付版本
    order.version = @"1.0";
    
    // NOTE: sign_type 根据商户设置的私钥来决定
    order.sign_type = (rsa2PrivateKey.length > 1)?@"RSA2":@"RSA";
    
    // NOTE: 商品数据
    order.biz_content = [APBizContent new];
    order.biz_content.body = @"我是测试数据";
    order.biz_content.subject = @"1";
    order.biz_content.out_trade_no = @"服务器返回的订单号"; //订单ID（由商家自行制定）
    order.biz_content.timeout_express = @"30m"; //超时时间设置
    order.biz_content.total_amount = [NSString stringWithFormat:@"%.2f", 0.01]; //商品价格
    
    //将商品信息拼接成字符串
    NSString *orderInfo = [order orderInfoEncoded:NO];
    NSString *orderInfoEncoded = [order orderInfoEncoded:YES];
    NSLog(@"orderSpec = %@",orderInfo);
    
    // NOTE: 获取私钥并将商户信息签名，外部商户的加签过程请务必放在服务端，防止公私钥数据泄露；
    //       需要遵循RSA签名规范，并将签名字符串base64编码和UrlEncode
    NSString *signedString = nil;
    APRSASigner* signer = [[APRSASigner alloc] initWithPrivateKey:((rsa2PrivateKey.length > 1)?rsa2PrivateKey:rsaPrivateKey)];
    if ((rsa2PrivateKey.length > 1)) {
        signedString = [signer signString:orderInfo withRSA2:YES];
    } else {
        signedString = [signer signString:orderInfo withRSA2:NO];
    }
    
    // NOTE: 如果加签成功，则继续执行支付
    if (signedString != nil) {
        //应用注册scheme,在AliSDKDemo-Info.plist定义URL types
        NSString *appScheme = @"alisdkdemo";
        
        // NOTE: 将签名成功字符串格式化为订单字符串,请严格按照该格式
        NSString *orderString = [NSString stringWithFormat:@"%@&sign=%@",
                                 orderInfoEncoded, signedString];
        
        // NOTE: 调用支付结果开始支付
        [[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
            NSLog(@"reslut = %@",resultDic);
        }];
    }
}
- (void)payView:(JPPayView *)view wechaeat:(NSMutableDictionary *)dict
{
    
    
    //需要创建这个支付对象
    
    PayReq *req   = [[PayReq alloc] init];
    
    //由用户微信号和AppID组成的唯一标识，用于校验微信用户
    
    req.openID = @"";
    
    // 商家id，在注册的时候给的
    
    req.partnerId = @"";
    
    // 预支付订单这个是后台跟微信服务器交互后，微信服务器传给你们服务器的，你们服务器再传给你
    
    req.prepayId  = @"";
    
    // 根据财付通文档填写的数据和签名
    
    req.package  = @"";
    
    // 随机编码，为了防止重复的，在后台生成
    
    req.nonceStr  = @"";
    
    // 这个是时间戳，也是在后台生成的，为了验证支付的
    
    NSString * stamp = @"";
    
    req.timeStamp = stamp.intValue;
    
    // 这个签名也是后台做的
    
    req.sign = @"";
    
    if ([WXApi sendReq:req]) { //发送请求到微信，等待微信返回onResp
        
        NSLog(@"吊起微信成功...");
        
    }else{
        
        NSLog(@"吊起微信失败...");
        
    }
}

- (void)loadPayList
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"key"] = DHNetworkManager.shareManager.userAccount.key;
    [DHNetworkManager.shareManager requestWithMethod:MethodPost UrlString:kPayListUrl params:dict
                                          completion:^(id json, BOOL isSuccess)
     {
         if (!isSuccess) {
             [SVProgressHUD showInfoWithStatus:@"请检查网络"];
             return ;
         }
         self.payView.payMemetList = [NSArray yy_modelArrayWithClass:[JPPayMentModel class] json:json[@"datas"]];
     }];
}

#pragma mark: - 设置TableView
- (void)setupTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.filterView.frame), kScreenWidth, self.view.bounds.size.height - CGRectGetMaxY(self.filterView.frame))];
    [self.view addSubview:self.tableView];
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self loadDataWithPullup:NO];
    }];
    MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        [self loadDataWithPullup:YES];
    }];
    self.tableView.mj_header = header;
    self.tableView.mj_footer = footer;
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.rowHeight = 120;
    [self.tableView registerNib:[UINib nibWithNibName:@"DHMyPostTaskCell" bundle:nil] forCellReuseIdentifier:mypostTaskCellID];
}
- (void)loadDataWithPullup:(BOOL)pullup
{
    if (pullup)
    {
        if (!self.model) {return;}
        if (self.model.hasmore.boolValue) {
            self.curpage++;
        }else{
            [self.tableView.mj_footer endRefreshingWithNoMoreData];
        }
    }
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"curpage"] = @(self.curpage);
    param[@"status"] = self.status;
    param[@"is_mouth"] = @"0";
    [DHNetworkManager.shareManager requestMyPostTaskWithParam:param completion:^(BOOL isSuccess, DHCleanOrderDataModel *model)
     {
         if (!isSuccess) {
             [self.tableView.mj_footer endRefreshing];
             [self.tableView.mj_header endRefreshing];
             return ;
         }
         if (pullup) {
             self.model.hasmore = model.hasmore;
             self.model.page_total = model.page_total;
             self.model.list = [self.model.list arrayByAddingObjectsFromArray:model.list];
             
             [self.tableView.mj_footer endRefreshing];
         }else{
             self.model = nil;
             self.model = model;
             [self.tableView.mj_header endRefreshing];
         }
    }];
    
}
#pragma mark: - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.model.list.count ;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DHMyPostTaskCell *cell = [tableView dequeueReusableCellWithIdentifier:mypostTaskCellID forIndexPath:indexPath];
    cell.model = self.model.list[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.delegate = self;
    return cell;
}

#pragma mark: - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DHOrderDetailController *detailVC = [[DHOrderDetailController alloc] init];
    detailVC.hidesBottomBarWhenPushed = true;
    
    NSString *strLongitude = self.strLongitude ? self.strLongitude : @"0";
    NSString *strLatitude = self.strLatitude ? self.strLatitude : @"0";
    
    //@{@"id":self.viewModel.listModel.list[indexPath.row].ID,@"lng":strLongitude,@"lat":strLatitude}
    NSMutableDictionary *requestInfo = [NSMutableDictionary dictionary];
    requestInfo[@"id"] = self.model.list[indexPath.row].ID;
    requestInfo[@"lng"] = strLongitude;
    requestInfo[@"lat"] = strLatitude;
    requestInfo[@"key"] = DHNetworkManager.shareManager.userAccount.key;
    requestInfo[@"store_id"] = self.model.list[indexPath.row].store_id;
    detailVC.requestInfo = requestInfo;
    
    [self.navigationController pushViewController:detailVC animated:true];
}

#pragma mark: - DHMyPostTaskCellDelegate
- (void)finishedCellNonePay:(DHMyPostTaskCell *)cell model:(DHCleanOrderModel *)model
{
    [UIView animateWithDuration:0.25 animations:^{
        self.payView.transform = CGAffineTransformTranslate(self.payView.transform, 0, -self.payView.bounds.size.height);
        NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
        dictM[@"price"] = model.pay_price;
        dictM[@"title"] = model.title;
        dictM[@"pay_id"] = model.pay_id;
        self.payView.dictM = dictM.copy;
    }];
}

- (void)finishedCellPayDone:(DHMyPostTaskCell *)cell model:(DHCleanOrderModel *)model
{

    switch (model.status.intValue) {
        case 0: // 编辑
        {
            JPPostTaskController *postVc = [JPPostTaskController postTaskVC];
            [self loadTaskDetailListWithID:model.ID postVc:postVc];
            postVc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:postVc animated:true];
        }
            break;
        case 1: // 确认完成
        {
            [self postFinishedOrderWithID:model.ID];
            NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
            dictM[@"key"] = DHNetworkManager.shareManager.userAccount.key;
            dictM[@"id"] = model.ID;
            dictM[@"order_id"] = model.order_id;
            dictM[@"cleaner_id"] = model.store_id;
            dictM[@"type"] = @"2";
            DHCommentController *commentVc = [[DHCommentController alloc] init];
            commentVc.postEvaParam = dictM.copy;
            commentVc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:commentVc animated:true];
        }
            break;
        default:
        {
            NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
            dictM[@"key"] = DHNetworkManager.shareManager.userAccount.key;
            dictM[@"id"] = model.ID;
            dictM[@"order_id"] = model.order_id;
            dictM[@"cleaner_id"] = model.store_id;
            dictM[@"type"] = @"2";
            DHCommentController *commentVc = [[DHCommentController alloc] init];
            commentVc.postEvaParam = dictM.copy;
            commentVc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:commentVc animated:true];
        }
            break;
    }
}
- (void)loadTaskDetailListWithID:(NSString *)ID postVc:(JPPostTaskController *)postVc
{
    NSString *url = [NSString stringWithFormat:@"%@%@",REMOTEURL,@"index.php?act=cleaning_info&op=getTaskDetail"];
    
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    dictM[@"key"] = DHNetworkManager.shareManager.userAccount.key;
    dictM[@"id"] = ID;
    dictM[@"lng"] = self.strLongitude;
    dictM[@"lat"] = self.strLatitude;
    
    [DHNetworkManager.shareManager requestWithMethod:MethodGet
                                           UrlString:url
                                              params:dictM.copy
                                          completion:^(id json, BOOL isSuccess)
     {
                                              
         if (!isSuccess) {
             [SVProgressHUD showInfoWithStatus:@"请检查网络"];
             return ;
         }
         
         postVc.changeInfo = [DHDetailModel yy_modelWithJSON:json[@"datas"][@"info"]];
         
     }];

}
#pragma mark: - 完成订单网络请求
- (void)postFinishedOrderWithID:(NSString *)ID
{
    NSString *url = [NSString stringWithFormat:@"%@%@",REMOTEURL,@"index.php?act=hotel_cleaning&op=runStoreDoneOrder"];
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    dictM[@"id"] = ID;
    dictM[@"key"] = DHNetworkManager.shareManager.userAccount.key;
    [DHNetworkManager.shareManager requestWithMethod:MethodPost UrlString:url params:dictM.copy completion:^(id json, BOOL isSuccess)
     {
         if (!isSuccess) {
             [SVProgressHUD showInfoWithStatus:@"请检查网络"];
             return ;
         }
         
         id temp = json[@"datas"];
         
         if (temp[@"succ"]) {
             [SVProgressHUD showSuccessWithStatus:temp[@"succ"]];
         }else{
             [SVProgressHUD showInfoWithStatus:temp[@"error"]];
         }
         
     }];
    
}
#pragma mark: - 设置导航栏
- (void)setupNavBar
{
    self.navigationController.navigationBar.hidden = false;
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:222.0f/255.0f green:60.0f/255.0f blue:50.0f/255.0f alpha:1];
    self.title = @"我发布的任务";
    [self.navigationController.navigationBar setTintColor:UIColor.whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont systemFontOfSize:17],
       NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
}


@end
